package com.xq.tmall.controller;

import com.xq.tmall.agu.ferign.StockSpider;
import com.xq.tmall.service.StockCodeInfoService;
import com.xq.tmall.service.StockFetchErrorService;
import com.xq.tmall.service.StockService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author chenguoxiang
 * @create 2018-03-27 11:14
 **/
@RequestMapping("/stock")
@Slf4j
@Controller
public class StockCtrl {

    @Autowired
    private StockService service;

    @Autowired
    private StockFetchErrorService stockFetchErrorService;

    @ApiOperation(value = "刷新代码", notes = "初始化所有代码")
    @ResponseBody
    @PostMapping(value = "/refresh_code")
    public String initCode(HttpServletRequest request,@RequestBody Map<String,Object> data) {
        try {

            //  stockCodeInfoService.getIp();
            service.getTodayCount();
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @ApiOperation(value = "竞价重新抓取", notes = "竞价重新抓取")
    @ResponseBody
    @GetMapping(value = "/refreshStockFetch")
    public String refreshStockFetch() {
        try {
           return stockFetchErrorService.refreshStockFetch("01");
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }


    @ApiOperation(value = "盘后数据抓取", notes = "盘后数据抓取")
    @ResponseBody
    @GetMapping(value = "/refreshStockFetchAfter")
    public String refreshStockFetchAfter() {
        try {
            return stockFetchErrorService.refreshStockFetch("02");
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }
}
